package model;

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;

import javax.imageio.ImageIO;

public class ScreenPrinter {
	Robot robot;
	String folder;
	Calendar startTime;
	String printTime;
	
	public ScreenPrinter(){
		try {
			this.robot = new Robot();
		} catch (AWTException e) {
			e.printStackTrace();
		}
		
		this.folder = ConstantsAndUtils.folder;
		File file = new File(this.folder);
		file.mkdir();
		
		startTime = Calendar.getInstance();
		printTime = String.valueOf(startTime.get(Calendar.DAY_OF_MONTH));
		printTime = printTime + "-" + startTime.get(Calendar.MONTH);
		printTime = printTime + "-" + startTime.get(Calendar.YEAR);
		printTime = printTime + "." + startTime.get(Calendar.HOUR);
		printTime = printTime + "-" + startTime.get(Calendar.MINUTE);
		printTime = printTime + "-" + startTime.get(Calendar.SECOND) + ".";

	}
	
	public void printScreen(int stepNumber, Rectangle rect){
		BufferedImage capturedImage = this.robot.createScreenCapture(rect);
		String fileName = this.folder + "\\" +printTime+ "passo" + stepNumber + ".jpg";
		try {
			ImageIO.write(capturedImage, "jpg", new File(fileName));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
